//获取应用实例
const app = getApp()
Page({
  data: {
    userInfo: {},
    hasUserInfo: false,
    canIUse: wx.canIUse('button.open-type.getUserInfo'),
    address: '',
    a:'',
    ad:''
  },
  bindKeyInput: function (e) {
    this.data.address = e.detail.value
  },
  onShow:function (){
    wx.request({
      url: 'https://hi.slickghost.com/WebTest/Operate',
      data: {
        choice: 'findemailmessage',
        openid: app.globalData.openid
      },
      header: {
        'content-type': 'json'
      },
      success: res => {
        app.globalData.email = res.data;
        this.setData({
          ad: res.data
        })
      }
    })
  },
  bindtest: function () {
    var t2=this;
    if (this.data.address != '') {
      wx.request({
        url: 'https://hi.slickghost.com/WebTest/Operate',
        data: {
          choice: 'checkemail',
          email: this.data.address 
        },
        header: {
          'content-type': 'json'
        },
        success: e => {
          var t3=t2;
          if (e.data == '0') {
            wx.showModal({
              title: '提示',
              content: '邮箱不存在，请重新输入'
            }),
              t3.setData({
                a:''
              }),
            this.data.address=''
          } else {
            app.globalData.email=this.data.address;
            wx.request({
              url: 'https://hi.slickghost.com/WebTest/Operate',
              data: {
                choice: 'insertemail',
                openid: app.globalData.openid,
                email: app.globalData.email
              },
              header: {
                'content-type': 'json'
              },
              success:res =>{
                this.data.address = ''
                wx.showToast({
                  title: '邮箱绑定成功！',
                  icon: 'success',
                  duration: 1000
                }),
                t3.setData({
                  a: ''
                }),
                  this.setData({
                  ad: app.globalData.email
                  })
              },
            })      
          }
        }
      })
    } else {
      this.data.address='',
      wx.showModal({
        title: '提示',
        content: '邮箱为空',
        success: function () {
        }
      })
    }
  }
})
